import openpyxl
import yaml


# 新建excel文件
# def new_file():
#     wb = openpyxl.Workbook('data.xlsx')
#     wb.create_sheet("data")
#     wb.save('data.xlsx')


# 从excel读取单行数据，两个参数：行号、列的数量
def select_from_excel(row, col):
    wb = openpyxl.load_workbook('data.xlsx')
    sheet = wb['data']
    data = []
    data_a = []
    for i in range(2, col + 2):
        data_a.append(sheet.cell(row=row, column=i).value)
    data.append(data_a)
    return data


# 从excel读取多行数据，三个参数：开始行、结束行、列的数量
def selects_from_excel(row1, row2, col2):
    wb = openpyxl.load_workbook('data.xlsx')
    sheet = wb['data']
    data = []
    for i in range(row1, row2 + 1):
        data_a = []
        for j in range(2, col2 + 2):
            data_a.append(sheet.cell(row=i, column=j).value)
        data.append(data_a)
    return data


# 从yaml文件中读取数据（只能读取全部数据）
def select_from_yaml():
    file = open(file='data.yaml', mode='r', encoding='utf-8')
    data = yaml.safe_load(file)
    return data


if __name__ == "__main__":
    c = select_from_yaml()
    print(c)
